package cn.fighter3.service.node;

import cn.fighter3.entity.node.Cnbook;
import cn.fighter3.entity.node.Fgbook;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;

public interface FgbookDao extends Neo4jRepository<Fgbook,String> {
    //Fgbook findByTitle(String title);
    //查询--按名字
    List<Fgbook> findByTitle(String title);
    //查询--按id
    Fgbook findByBookId(String id);
    //模糊查询
//    @Query("match(n:Fgbook) where n.title =~'.*{name}.*' return n")
//    Fgbook find(@Param(value="name") String name);
    List<Fgbook> findByTitleLike(String name);

    //删除
    void deleteByBookId(String id);

    @Query("match (n:Fgbook) where n.title=$title detach delete n")
    void deleteByTitle(String title);

    //更新修改
    @Query("match (n:Fgbook) where n.bookId = $id set n.title = $title, n.M_PUBLISHER = $publish, n.M_CALL_NO = $call, n.m_PUB_YEAR = $year return n")
    Fgbook updateByNode(String id,String title,String publish,String call,String year);

    //@Query("match (n:Fgbook) return n limit 25")
    @Query("match (a:Fgbook)-[r]->(b) return a,count(r) order by count(r) DESC limit 20")
    List<Fgbook> all2();

    //查询关系数量
    //MATCH (n:Fgbook {bookId:$id})-[]-() RETURN count(*)
    //profile match (n:Fgbook) where n.bookId = $id return size((n)-[]-())
    @Query("MATCH (n:Fgbook {bookId:$id})-[]-() RETURN count(*)")
    Integer countfg(String id);
}
